<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017\11\1 0001
 * Time: 16:03
 */
namespace app\admin\controller;
use think\Controller;
use think\Auth;
use  think\Session;
use think\Request;
class Base extends Controller{

/*
 *
 * 是否登录
 * */
    public function isLogin(){
        $res= Session::get('STAFF');
        if(empty($res)){
//            $this->error('请先登录',url('admin/index/login'),1);
            $this->redirect('admin/index/login');
        }else{
            return true;
        }
    }

    /***
    *权限控制
     */
    public function _initialize() {
        $controller = request()->controller();
        $Auth = new Auth();
        $id = Session::get("STAFF.staff_id");
        if($controller != 'Index'){//首页都有权限
            $request = Request::instance();
            if (!$Auth->check($request->module() . '/' . $request->controller() . '/' . $request->action(), $id)){
                header("Content-type: text/html; charset=utf-8");
                echo '<p style="margin:10px;text-align:center;">对不起，您没有权限操作此模块！</p>';
                exit();
            }
        }
    }


}